package cn.lx.es.query.processor;

import cn.lx.es.query.annotation.SearchProcessor;
import cn.lx.es.query.annotation.TermSearch;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.lang.reflect.Field;

/**
 * @author wcy
 * @version 1.0
 * @description: 内置处理器 - 精确匹配处理器
 * @date 2025-07-02 下午1:21
 */
@SearchProcessor
public class SearchTermProcessor implements SearchAnnotationProcessor<TermSearch> {
    @Override
    public void process(TermSearch annotation, Field field, Object value, BoolQueryBuilder boolQueryBuilder) {
        if (value != null) {
            boolQueryBuilder.must(QueryBuilders.termQuery(field.getName(), value));
        }
    }
    @Override
    public Class<TermSearch> getAnnotationType() {
        return TermSearch.class;
    }
}
